package com.example.singletones;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class WebCommunicator {
	private static WebCommunicator instance = null;

	protected WebCommunicator() {
		// Exists only to defeat instantiation.
	}

	public static WebCommunicator getInstance() {
		if (instance == null) {
			instance = new WebCommunicator();
		}
		return instance;
	}

	public String getRequest(String url) {
		URL mUrl;
		String fullInput = "";
		try {
			mUrl = new URL(url);
			URLConnection yc = mUrl.openConnection();
			BufferedReader in = new BufferedReader(new InputStreamReader(
					yc.getInputStream()));
			String inputLine;

			while ((inputLine = in.readLine()) != null)
				fullInput = fullInput + inputLine;
			in.close();
		} catch (MalformedURLException e) {
			fullInput = e.getMessage();
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fullInput = e.getMessage();
		}
		return fullInput;
	}

}
